#include "data.h"
#include "datacenter.h"
#include "interview.qpb.h"

model::UserInfo *model::DataCenter::getMyself()
{
    static model::UserInfo* info = new model::UserInfo();
    info->userId = "user-guest";
    info->avatar = QPixmap(":/ui/btn_close_50.png");
    info->nickname = "游客";
    return info;
}

void model::DataCenter::searchInterviewAsync(const SearchLimits &limits)
{
    _netClient.searchInterview(limits);
}

QList<model::InterviewInfo> *model::DataCenter::getSearchInterviewResult()
{
    return _searchInterviewResult;
}

void model::DataCenter::resetSearchInterviewResult(std::shared_ptr<quan_mian::SearchInterviewRsp> rsp)
{
    if (_searchInterviewResult == nullptr)
        _searchInterviewResult = new QList<InterviewInfo>();

    _searchInterviewResult->clear();

    for(const auto& interview : rsp->interviewList())
        _searchInterviewResult->append(interview);
}

void model::DataCenter::searchQuestionClusterAsync(const SearchLimits &limits)
{
    _netClient.searchQuestionCluster(limits);
}

QList<model::QuestionClusterInfo> *model::DataCenter::getSearchQuestionClusterResult()
{
    return _searchQuestionClusterResult;
}

void model::DataCenter::resetSearchQuestionClusterResult(std::shared_ptr<quan_mian::SearchQuestionClusterRsp> rsp)
{
    if (_searchQuestionClusterResult == nullptr)
        _searchQuestionClusterResult = new QList<QuestionClusterInfo>();

    _searchQuestionClusterResult->clear();

    for(const auto& questionCluster : rsp->questionClusterList())
        _searchQuestionClusterResult->append(questionCluster);
}

void model::DataCenter::searchCompanyAsync(const SearchLimits &limits)
{
    _netClient.searchCompany(limits);
}

QList<model::CompanyInfo> *model::DataCenter::getSearchCompanyResult()
{
    return _searchCompanyResult;
}

void model::DataCenter::resetSearchCompanyResult(std::shared_ptr<quan_mian::SearchCompanyRsp> rsp)
{
    if (_searchCompanyResult == nullptr)
        _searchCompanyResult = new QList<CompanyInfo>();

    _searchCompanyResult->clear();

    for(const auto& company : rsp->companyList())
        _searchCompanyResult->append(company);
}

void model::DataCenter::uploadInterviewAsync(const InterviewInfo &interview)
{
    _netClient.uploadInterview(interview);
}
